package com.wt.springsamples.common;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class LinuxUtils {

    public static void execCmd(String cmd){
        System.out.println("got cmd job : " + cmd);
        try {
            Process process = Runtime.getRuntime().exec(cmd);
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(),"gbk"));
            String result;
            while ((result = br.readLine())!=null) {
                System.out.println("linux命令result [" + result + "]");
            }
            br.close();
            //process.waitFor();
            process.destroy();
        } catch (Throwable e) {
            System.err.println("执行linux命令出错:" + e.getMessage());
            e.printStackTrace();
        }
    }

    public  static void main(String[] args){
        LinuxUtils.execCmd(" ping 172.18.155.184");
    }
}
